﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using DTO;
namespace DAO
{
   public class ChangBayDAO
    {
        DataTable dt;
        List<string> dsThamSo;
        ArrayList dsGiaTri;
       
        
        public ChangBayDAO()
        {
            dt = new DataTable();
            dsThamSo = new List<string>();
            dsGiaTri = new ArrayList();
            
        }
       public DataTable layThongTinChangBay()
       {
           dt = DataProvider.ExecuteStoreProc("XemThongTinChangBay", null, null);
           return dt;
       }
       public int capNhatChangBay(ChangBayDTO cb)
       {
           int n = 0;
           string sql = "update ChangBay set ID_sanBayDi = '" + cb.MaSanBayDi +"' , ID_sanBayDen= '"+cb.MaSanBayDen+"',soDam = "+cb.SoDam+",nhienLieuDuKien = " + cb.NhienLieuDuKien + " where ID_changBay = '" +cb.MaChangBay+ "'";
           n = DataProvider.ExecuteNoneQuery(sql);
           return n;
       }
       public int capNhatChangBay(string maChangBay)
       {
           int n = 0;
           string sql = "update ChangBay set tinhTrang = 'True' where ID_changBay = '" + maChangBay + "'";
           n = DataProvider.ExecuteNoneQuery(sql);
           return n;
       }
       public int themChangBay(ChangBayDTO cb)
       {
           int n = 0;
           string sql = "insert into ChangBay(ID_sanBayDi,ID_sanBayDen,soDam,nhienLieuDuKien,tinhTrang) values('" + cb.MaSanBayDi + "' ,'" + cb.MaSanBayDen + "'," + cb.SoDam + ", " + cb.NhienLieuDuKien + ",'False')";
           n = DataProvider.ExecuteNoneQuery(sql);
           return n;
       }
     
       public bool kiemTraChangBay(string maSanBayDi, string maSanBayDen)
       {
           dsThamSo = new List<string>();
           dsGiaTri = new ArrayList();
           dsThamSo.Add("@maSanBayDi");
           dsThamSo.Add("@maSanBayDen");

           dsGiaTri.Add(maSanBayDi);
           dsGiaTri.Add(maSanBayDen);

           dt = DataProvider.ExecuteStoreProc("sp_kiemTraChangBay", dsThamSo, dsGiaTri);
           if (dt.Rows.Count > 0)
           {
               return false;
           }
           return true;
       }
       public DataTable layThongTinChangBay(string maSanBayDi, string maSanBayDen)
       {
           dsThamSo = new List<string>();
           dsGiaTri = new ArrayList();
           dsThamSo.Add("@maSanBayDi");
           dsThamSo.Add("@maSanBayDen");

           dsGiaTri.Add(maSanBayDi);
           dsGiaTri.Add(maSanBayDen);

           dt = DataProvider.ExecuteStoreProc("sp_XemThongTinChangBay_SanBayDi_SanBayDen", dsThamSo, dsGiaTri);
           return dt;
       }
       public DataTable layThongTinSanBayDiDen_ChangBay()
       {
           dt = DataProvider.ExecuteStoreProc("sp_loadChangBayFull",null,null);
           return dt;
       }
       public string laySanBayDenCuaChangBay(int maChangBay)
       {
           dsThamSo = new List<string>();
           dsGiaTri = new ArrayList();
           dsThamSo.Add("@maChangBay");

           dsGiaTri.Add(maChangBay);

           dt = DataProvider.ExecuteStoreProc("sp_layNoiDenCuaChangBay", dsThamSo, dsGiaTri);
           return dt.Rows[0]["ID_sanBayDen"].ToString();
          
       }
     
    }
}
